var prefix = jsctx + "/withdrawManager";

var withdrawManager = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    function reset() {
        $("#memberType").val('');
        $("#memberIdAndNickname").val("");
    }

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 40;

    // var pageNumber = sessionStorage.getItem("pageNumber",)
    function load() {
        // alert($('#exampleTable').bootstrapTable('getOptions').pageNumber);
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listWithdrawMagVo",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    showColumns: true,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            memberType: $('#memberType').val().trim(),
                            memberIdAndNickname: $('#memberIdAndNickname').val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'memberId', title: '客户ID', width: '100'},
                        {field: 'name', title: '客户名称', width: '150'},
                        {field: 'memberType', title: '客户类型', width: '100'},
                        {field: 'allAmount', title: '总收益', width: '100'},
                        {field: 'firstRecharge', title: '新用户返点', width: '100'},
                        {field: 'mutiRecharge', title: '复充返点', width: '100'},
                        {field: 'incomeAmount', title: '可提现金额', width: '100'},
                        {field: 'allTransferAmount', title: '已提现金额', width: '100'},
                        {
                            title: '操作',
                            field: 'roleId',
                            width: '100',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var a = '';
                                var b = '';
                                var d = '';
                                if (FinanceManage_tenantOperator_update) {
                                    a = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="明细" onclick="withdrawManager.detail(\''
                                        + row.memberId
                                        + '\')">明细</a> ';
                                }
                                return a;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function detail(memberId) {
        location.href = prefix + "/listDetail/" + memberId;
    }


    function exportAcctTenantOperator() {
        $.fileDownload(jsctx + "/tenantOperator/exportTenantOperator", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                operatorName: $("#operatorName").val().trim(),
                loginName: $("#loginName").val().trim(),
                contactName: $("#contactName").val().trim(),
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    /**
     * 导出列表
     */
    function exportList() {
        $.fileDownload(prefix + "/export", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                memberIdAndNickname: $('#memberIdAndNickname').val().trim(),
                memberType: $('#memberType').val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        exportList: exportList,
        reset: reset,
        detail: detail
    };
})();
